$(function(){
		// var key = getcookie('doutingshop');
		// if(key==''){
		// 	location.href = 'login.html';
		// }
		//初始化列表
		function initPage(){
			$.ajax({
				type:'post',
	            url:ApiUrl+'/user/eb/getDeliveryAddressPage',
	            dataType:'json',
				success:function(result){
					checklogin(result.rspCode);
					if(result.rspCode!=0 || result.rows==null){
						return false;
					}
					var html = template.render('saddress_list', result);
					$("#address_list").empty();
					$("#address_list").append(html);
					//点击删除地址
					$('.deladdress').click(function (){
						$this= $(this);
						var address_id = $this.attr('address_id');
						$.ajax({
							type:'post',
							url:ApiUrl+'/user/eb/deleteDeliveryAddress/'+address_id,
							dataType:'json',
							success:function(result){
								checklogin(result.rspCode);
			                    if (result.rspCode==0) {
			                        $this.parents('li').remove();
			                    };
								
							}
						});
					});
					//点击设置默认地址
					$('.addr-default').click(function (){
						$this= $(this);
						var address_id = $this.attr('address_id');
						if ($this.find('.fa-check-circle').length>0) {
							return false;
						};
						$.ajax({
			        		type:'post',
			        		url:ApiUrl+'/user/eb/defaultDeliveryAddress/'+address_id,
			        		dataType:'json',
			        		success:function(result){
			        			checklogin(result.rspCode);
			        			if(result.rspCode==0){
			                        $('.fa-check-circle').removeClass('fa-check-circle').addClass('fa-circle-o');
			                        $this.find('i').removeClass('fa-circle-o').addClass('fa-check-circle');
			                    }
			        		}
			        	});
					});
				}
			});
		}
		initPage();

});